
def f(n):
    rn = list(str(n))
    rn.reverse()
    rn = ''.join(rn)
    return str(n) == rn

ans = 0
for i in xrange(1, 1000000):
    if f(i):
        sb = '{0:b}'.format(i)
        if f(sb):
            ans += i

print ans

